<template>
    <div class="login_container">
      <div class="login_box">
        <!-- 头像 -->
        <div class="avatar">
          <img src="../assets/nike.png" alt="" />
        </div>
        <!-- 登录表单 -->
        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginFormRules"
          label-width="0px"
          class="login_form"
        >
          <!-- 用户名 -->
          <el-form-item prop="username">
            <el-input
              v-model="loginForm.username"
              prefix-icon="iconfont icon-user"
            ></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              prefix-icon="iconfont icon-password"
              type="password"
            ></el-input>
          </el-form-item>
          <el-form-item class="btns">
            <el-button type="primary" @click="login">登录</el-button>
            <el-button type="danger" @click="resetLoginForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="wavesDIV" style="display: block">
      <svg
        class="waves"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        viewBox="0 24 150 28"
        preserveAspectRatio="none"
        shape-rendering="auto"
      >
        <defs>
          <path
            id="gentle-wave"
            d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"
          ></path>
        </defs>
        <g class="parallax">
          <use
            xlink:href="#gentle-wave"
            x="48"
            y="-2"
            fill="rgba(125, 191, 185,0.3)"
          ></use>
          <use
            xlink:href="#gentle-wave"
            x="48"
            y="3"
            fill="rgba(125, 191, 185,0.5)"
          ></use>
          <use
            xlink:href="#gentle-wave"
            x="48"
            y="5"
            fill="rgba(125, 191, 185,0.7)"
          ></use>
          <use
            xlink:href="#gentle-wave"
            x="48"
            y="12"
            fill="rgba(125, 191, 185,1)"
          ></use>
        </g>
      </svg>
    </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      // 登录表单数据对象
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      // 表单验证规则
      loginFormRules: {
        username: [
          { required: true, message: '请输入登录名称', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          {
            min: 6,
            max: 15,
            message: '长度在 6 到 15 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // 重置按钮
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    // 登录
    login() {
      this.$refs.loginFormRef.validate(async (vaild) => {
        // eslint-disable-next-line no-useless-return
        if (!vaild) return
        const { data: res } = await this.$http.post('login', this.loginForm)
        // console.log(res)
        if (res.meta.status !== 200) {
          return this.$message.error('登录失败')
        } else {
          this.$message.success('登录成功')
        }
        window.sessionStorage.setItem('token', res.data.token)
        this.$router.push('/home')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login_container {
  background-image: linear-gradient(to top, #ffffff 20%, #7ac5bf 80%);
  height: 100%;
}
.login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 20px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  .avatar {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    img {
      background-color: rgb(0, 0, 0);
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
}
.btns {
  display: flex;
  justify-content: flex-end;
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
body{
  margin: 0;
}
.wavesDIV{
    z-index: 1;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 1vh;
    background-color: rgb(212, 235, 233);
    /* border: 1px solid black; */
}

.waves {
    position: relative;
    width: 100%;
    height: 15vh;
    margin-top: -15vh;
    min-height: 100px;
    max-height: 150px;
    /* border: 1px solid black; */

}
/* 选择所有子元素 */
.parallax>use{
  /* 将动画与元素绑定 cubic-bezier贝塞尔曲线 改变值可以控制速度 */
  animation: move-forever 25s cubic-bezier(.55,.5,.45,.5) infinite;
}
/* 选择子元素中的第几个 */
.parallax>use:nth-child(1){
  /* 规定在动画开始之前的延迟。 */
  animation-delay: -2s;
  /* 规定完成动画所花费的时间，以秒或毫秒计。 */
  animation-direction: 7s;
}
.parallax>use:nth-child(2){
  animation-delay: -3s;
  animation-direction: 10s;
}
.parallax>use:nth-child(3){
  animation-delay: -4s;
  animation-direction: 13s;
}
.parallax>use:nth-child(4){
  animation-delay: -5s;
  animation-direction: 15s;
}

/* 动画 */
@keyframes move-forever {
  0%{
    transform: translate3d(-90px,0,0);
  }
  100%{
    transform: translate3d(85px,0,0);
  }
}
</style>
